package com.xx.job.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xx.job.controller.dto.PageDTO;
import com.xx.job.entity.system.SysOperaLog;
import com.xx.job.mapper.SysOperaLogMapper;
import com.xx.job.service.system.SysOperaLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liangcy
 * @since 2021-01-14
 */
@Service
public class SysOperaLogServiceImpl extends ServiceImpl<SysOperaLogMapper, SysOperaLog> implements SysOperaLogService {

    @Autowired
    private SysOperaLogMapper sysOperaLogMapper;

    @Override
    public int add(SysOperaLog sysOperaLog) {
        return sysOperaLogMapper.insert(sysOperaLog);
    }

    @Override
    public int delete(Long id) {
        return sysOperaLogMapper.deleteById(id);
    }

    @Override
    public int update(SysOperaLog sysOperaLog) {
        return sysOperaLogMapper.updateById(sysOperaLog);
    }

    @Override
    public SysOperaLog select(Long id) {
        return sysOperaLogMapper.selectById(id);
    }

    @Override
    public IPage<SysOperaLog> selectPage(PageDTO pageDTO, SysOperaLog sysOperaLog) {
        IPage<SysOperaLog> page = new Page<>(pageDTO.getPageIndex(),pageDTO.getPageSize());
        QueryWrapper<SysOperaLog> wrapper = new QueryWrapper<>();
        if(StringUtils.isNotBlank(sysOperaLog.getTitle())){
            wrapper.like("title",sysOperaLog.getTitle().trim());
        }
        if(StringUtils.isNotBlank(sysOperaLog.getOperName())){
            wrapper.like("oper_name",sysOperaLog.getOperName().trim());
        }
        if(StringUtils.isNotBlank(sysOperaLog.getBusinessType())){
            wrapper.eq("business_type",sysOperaLog.getBusinessType().trim());
        }
        if(StringUtils.isNotBlank(sysOperaLog.getStatus())){
            wrapper.eq("status",sysOperaLog.getStatus());
        }
        IPage<SysOperaLog> sysOperaLogIPage = sysOperaLogMapper.selectPage(page, wrapper);
        return sysOperaLogIPage;
    }
}
